<template>
  <div class="container">
    <!-- 左侧菜单栏 -->
    <div class="sidebar">
      <div class="logo">AutoWorks</div>
      <div
        class="menu-item"
        v-for="(item, index) in menuItems"
        :key="index"
        :class="{ active: currentMenu === item.key }"
        @click="goto(item.key)"
      >
        {{ item.label }}
      </div>
    </div>

    <!-- 右侧内容区 -->
    <div class="main-content">
      <router-view />
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref, watchEffect } from 'vue';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
const otpList = ref([]);
// 添加菜单相关的状态
const menuItems = ref([
  { key: 'otp', label: 'OTP管理' },
  { key: 'pass', label: '账号管理' },
  { key: 'setting', label: '设置' },
  { key: 'export', label: '导出导入' },
  { key: 'settings', label: '关于' },
]);
const currentMenu = ref('');
watchEffect(() => {
  currentMenu.value = route.name?.toString() || 'otp';
});
const goto = (key: string) => {
  currentMenu.value = key;
  router.push(key);
};
onMounted(() => {
  console.log(route, currentMenu);
});
</script>

<style scoped lang="scss">
@use '../vars.scss';
.container {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 200px;
  background-color: #f5f5f5;
  border-right: 1px solid #e8e8e8;
  .logo {
    font-size: 20px;
    font-weight: bold;
    padding: 10px 20px;
  }

  .menu-item {
    padding: 12px 24px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.3s;

    &:hover {
      background-color: #e6e6e6;
    }

    &.active {
      background-color: #e6f7ff;
      color: #1890ff;
      border-right: 3px solid #1890ff;
    }
  }
}

.main-content {
  flex: 1;
  padding: 10px 20px;
  background-color: #ffffff;

  .content-section {
    height: 100%;
  }
}

// 保留原有的 .content 样式
.content {
  background-color: #fff;
  height: 50px;
  display: flex;
  align-items: center;
  border-radius: 10px;
  cursor: pointer;
  padding: 0 10px;
  gap: 10px;
  margin-bottom: 10px;
  border: 1px solid #e8e8e8;

  .countdown {
    font-size: 14px;
  }

  .title {
    font-size: 22px;
    font-weight: bold;
  }
}

button {
  margin-right: 10px;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  background-color: #1890ff;
  color: white;
  cursor: pointer;

  &:hover {
    background-color: #40a9ff;
  }
}
</style>
